<template>
  <div class="follow_detail">
    <div class="common_bg" v-if="followList.length != 0"></div>

    <div class="container">
      <div class="follow_item" @click="toFollowDetail(item)" v-for="(item, index) in followList" :key="index" >
        <!-- <van-swipe-cell> -->
          <div class="card base_card">
            <div class="card_title_box">
              <div class="card_title">
                <i class="icon_phone_follow"></i>
                <span>{{item.followTypeRemark}}</span>
                <span class="intention_level" v-if="item.strengthRemark">意向 : {{item.strengthRemark}}</span>
                <span class="follow_num">第{{followList.length - index}}次</span>
              </div>
            </div>

            <div class="card_content">
              <div>
                <i class="icon_follow1"></i>
                <span  class="follow_result_label">连接情况 : <span class="follow_result_text">{{item.connectionRemark}}</span></span>
              </div>
              <div>
                <i class="icon_follow2"></i>
                <span class="follow_result_label">跟进结果 : <span class="follow_result_text">{{item.followResultRemark}}</span></span>
              </div>
              <div class="follow_result_remark">
                <p>{{item.remark}}</p>
                <span class="current_follow_time">本次跟进时间 : {{item.createTime}}</span>
                <i class="icon_follow_level" :class="computenIconFollowLevel(item)"></i>
              </div>
            </div>
            
            <!-- <van-divider dashed style="margin: 5px 0 2px;" /> -->

            <div class="card_footer">
              <div>下次跟进方向 : {{item.nextFollowRemark}}</div>
              <div>下次跟进时间 : {{item.nextFollowTime}}</div>
            </div>


            
          </div>

          <!-- <template slot="right">
            <div class="btn_follow">
              <van-button square type="primary" text="优先跟进" @click="deleteParent(index)" />
              <van-button square type="danger" text="停止跟进" @click="deleteParent(index)" />
            </div>
          </template> -->
        <!-- </van-swipe-cell> -->
      </div>

      <div v-if="followList.length == 0" class="noData">
        <img src="../../../assets/img/nodata.png" alt="">
        <p>暂时还没有数据</p>
        <p>快来手动添加吧</p>
        <span class="addData" @click="addFollow">添加</span>
      </div>
    </div>

    <div class="icon_place" @click="followPopup.status = true; followPopup.title='跟进设置'">
    </div>

    <div class="btn_add btn_circle" v-if="followList.length != 0" @click="addFollow">
      <i></i>
    </div>

    <!-- 添加跟进 -->
    <van-popup v-model="followPopup.status" class="popup" position="right" :style="{ height: '100%', width: '100%', background: '#F7F9FF' }">
      <div class="top_bar pop_top_bar">
        <span class="icon_left" @click="followPopup.status = false;"></span> 
        <span class="title">{{followPopup.title}}</span> 
        <span @click="update" v-if="followPopup.title == '跟进设置'">完成</span>
        <span @click="save"   v-if="followPopup.title == '添加跟进'">完成</span>
        <span    v-if="followPopup.title == '跟进详情'"></span>
      </div>

      <div class="common_bg"></div>
      <div class="container">
        <div class="settingFollow" v-if="followPopup.title == '跟进设置'">
          <van-switch-cell active-color="#80D784" v-model="updateFollow.followLevelStatus" title="停止跟进" />

          <van-cell :value="updateFollow.personName" is-link @click="showBottomSelect('salePerson')">
            <template slot="title">
              <span class="custom-title">跟进顾问</span>
            </template>
          </van-cell>

          <van-cell-group>
            <van-field
              v-model="updateFollow.remark"
              rows="3"
              autosize
              label="备注"
              type="textarea"
              maxlength="140"
              placeholder="请输入备注"
              show-word-limit
            />
          </van-cell-group>
        </div>

        <div v-if="followPopup.title == '添加跟进'"  class="add_follow_box">
          <div class="follow_methods">
            <ul class="list">
              <li v-for="(item, index) in followMethodsList" @click="showMethodsPop(item)" :key="index">
                <van-cell :value="followData[item.type].value" is-link >
                  <template slot="title">
                    <img :src="item.icon" class="icon_methods" alt="">
                    <span class="custom-title">{{item.label}}</span>
                  </template>
                </van-cell>
              </li>

              <!-- :value="followData[item.type].value" -->
              <li class="added_Methods" v-for="(item, index) in followMethodsListAdd" @click="showMethodsPopAdd(item, index)" :key=" 'add' + index">

                <van-swipe-cell :name='item.id' :on-close="onClose2" >
                  <van-cell :value="followMethodsListAddData[index].followDataRemark" is-link>
                    <template slot="title">
                      <img :src="item.icon" class="icon_methods" alt="">
                      <span class="custom-title">{{item.label}}</span>
                    </template>
                  </van-cell>
                  <template v-if="showAddLabel" slot="right">
                    <van-button square type="danger" text="删除" />
                  </template>
                </van-swipe-cell>

              </li>


              
              <div class="btn_addMethods" v-if="showAddLabel" @click="addFollowLabel">
                <i class="icon_add2"></i>
                <span>添加</span>
              </div>
            </ul>
          </div>

          <div class="follow_remark">
            <div class="card_title card_title_box ">
              <i class="icon_remark"></i>
              <span>备注</span>
            </div>
            <van-cell-group>
              <van-field
                v-model="addForm.remark"
                rows="3"
                autosize
                type="textarea"
                maxlength="140"
                placeholder="请输入备注"
                show-word-limit
              />
            </van-cell-group>
          </div>

          <div class="next_follow_info">
            <van-cell :value="addForm.nextFollowTime" is-link @click="showBottomSelect('date')">
              <template slot="title">
                <span class="custom-title">下次跟进时间</span>
              </template>
            </van-cell>
            <van-cell :value="followData.nextFollow.value" is-link @click="showMethodsPop({ label: '跟进方向',type: 'nextFollow'})">
              <template slot="title">
                <span class="custom-title">下次跟进方向</span>
              </template>
            </van-cell>
            <van-radio-group v-model="addForm.followLevel">
              <van-cell-group>
                <van-cell title="优先跟进" clickable @click="clickRadio('1')">
                  <van-radio slot="right-icon" name="1" />
                </van-cell>
                <van-cell title="停止跟进" clickable @click="clickRadio('0')">
                  <van-radio slot="right-icon" name="0" />
                </van-cell>
              </van-cell-group>
            </van-radio-group>
          </div>
        </div>

        <div v-if="followPopup.title == '跟进详情'"  class="add_follow_box">
          
        </div>


        
      </div>
      
    </van-popup>
    <!-- 添加跟进 -->

    <van-popup v-model="methodsPopStatus" class="screen_box" position="right" :style="{ height: '85%', }">
      <div class="screen_title_box" style="background: #fff">
        <i class="icon_return" @click="methodsPopStatus = false"></i>
        <span class="screen_title">{{methodsPopTitle}}</span>
        <span class="btn_confirm"  @click="addMethodsItem">添加</span>
      </div>
      <div class="screen_lisvaluet">
        <div @click="clickMethods(item)" v-for="(item, index) in followMethodsRadioList" :key="index">
          <van-swipe-cell :name='item.followDataId' :on-close="onClose" >
            <van-cell :border="false" :title="item.followDataRemark" />
            <template slot="right">
              <van-button square type="danger" text="删除" />
            </template>
          </van-swipe-cell>
        </div>

      </div>
    </van-popup>

    <van-dialog
      v-model="showAddPop"
      title="添加"
      show-cancel-button
      :beforeClose="beforeCloseDialog"
      class="dialog"
    >
      <van-field v-model="addMethodsValue" placeholder="请输入" />
    </van-dialog>

    <van-popup v-model="bottomSelectStatus"  position="bottom" :style="{ height: '40%', }">
      <van-datetime-picker
        v-if="bottomSelectType == 'date'"
        :min-date="minDate"
        :formatter="formatter"
        type="datetime"
        @cancel="onCancel"
        @confirm="onConfirm"
      />

      <van-picker
        v-else
        show-toolbar
        title="请选择"
        value-key="label"
        :columns="bottomAreaList"
        @cancel="onCancel"
        @confirm="onConfirm"
      />
    </van-popup>





    

  </div>
</template>

<style>
.screen_lisvaluet .van-swipe-cell{
  border-bottom: .51px solid #F0F0F0;
}
.popup .van-field__body {
  height: auto !important;
}

.follow_detail .list .van-cell__title {
  display: flex;
  align-items: center;
}

.follow_detail .added_Methods .van-swipe-cell {
  border-top: .6px solid #e9e9e9;
}

</style>
<style scoped>
.follow_detail .settingFollow {
  box-shadow: 0px 0px 4px 3px rgba(216,216,216,0.5);
}
.follow_detail .btn_addMethods {
  padding: .266667rem 0;
  margin-bottom: .133333rem;
  display: flex;
  justify-content: center;
  align-items: center;
}
.follow_detail .btn_addMethods span {
  font-size: .32rem;
  color: #FFC834;
}

.follow_detail .btn_follow {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 1.066667rem;
}
.follow_detail .btn_follow button {
  height: 50%;
}

.follow_detail .icon_methods {
  display: inline-block;
  width: .76rem;
  height: .746667rem;
  margin-right: .133333rem;
}
.follow_detail .add_follow_box > div {
  background: #fff;
  border-radius: .4rem;
  overflow: hidden;
  margin-bottom: .533333rem;
  box-shadow:0px 0px 4px 4px rgba(234,233,233,0.5);
}

.follow_detail .popup .container {
  /* background: #fff; */
  border-radius: .36rem;
  margin: 1.146667rem .266667rem 0 ;
  overflow: hidden;
  padding: 0;
}

.follow_detail .screen_title_box {
  background: #303133;
}
.follow_detail .follow_setting {
  position: fixed;
  top: .266667rem;
  right: .266667rem;
  color: #fff;
  z-index: 99;
  font-size: .426667rem;
}

.follow_detail .intention_level {
  display: inline-block;
  padding: 0 3px;
  box-sizing: border-box;
  font-size: .32rem;
  color: #fff;
  background: #8B9DFB;
  margin-left: .186667rem;
  margin-top: 1px;
  line-height: .533333rem;
  border-radius: .106667rem
}
.follow_detail .follow_num {
  margin-left: auto;
  width: 1rem;
  height: .32rem;
  font-size: .226667rem;
  border-radius: .16rem;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-right: .266667rem;
}
.follow_detail .container {
  position: relative;
  padding: .4rem .266667rem 0;
}

.follow_detail .follow_item {
  margin-bottom: .533333rem;
}

.follow_detail .follow_item:nth-of-type(1n) .base_card {
  border-color: #8884C3;
}
.follow_detail .follow_item:nth-of-type(2n) .base_card {
  border-color: #FE8697;
}
.follow_detail .follow_item:nth-of-type(3n) .base_card {
  border-color: #FFC834;
}

.follow_detail .follow_item:nth-of-type(1n) .follow_num {
  background: #8884C3;
}
.follow_detail .follow_item:nth-of-type(2n) .follow_num {
  background: #FE8697;
}
.follow_detail .follow_item:nth-of-type(3n) .follow_num {
  background: #FFC834;
}

.follow_detail .icon_phone_follow {
  display: inline-block;
  width: .546667rem;
  height: .6rem;
  background: url('../../../assets/img/icon_phone_follow.png') 0 0 no-repeat;
  background-size: 100%;
}

.follow_detail .card_content {
  background: #F7F9FF;
  font-size: .32rem;
  color: #666666;
  padding:  .133333rem .266667rem;
  box-sizing: border-box;
}

.follow_detail .card_content > div {
  margin-bottom: .133333rem;
}

.follow_detail .icon_follow1 {
  display: inline-block;
  width: .4rem;
  height: .28rem;
  background: url('../../../assets/img/icon_follow1.png') 0 0 no-repeat;
  background-size: 100%;
}
.follow_detail .icon_follow2 {
  display: inline-block;
  width: .333333rem;
  height: .346667rem;
  background: url('../../../assets/img/icon_follow2.png') 0 0 no-repeat;
  background-size: 100%;
  margin-left: .066667rem;
}
.follow_detail .follow_result_label {
  margin-left: .133333rem;
}
.follow_detail .follow_result_remark {
  position: relative;
  color: #B7B7B7;
}
.follow_detail .icon_follow_level {
  display: inline-block;
  width: 1.066667rem;
  height: 1.066667rem;
  position: absolute;
  right: .386667rem;
  bottom: 0;
}
.icon_follow_level_first{
  background: url('../../../assets/img/icon_follow_level_first.png') 0 0 no-repeat;
  background-size: 100%;
}
.icon_follow_level_stop{
  background: url('../../../assets/img/icon_follow_level_stop.png') 0 0 no-repeat;
  background-size: 100%;
}

.follow_detail .card_content > div:first-child .follow_result_text {
  color: #FFCA3A;
}
.follow_detail .card_content > div:nth-child(2) .follow_result_text {
  color: #E5A4DD;
}

.follow_detail .current_follow_time {
  font-size: .266667rem;
  display: inline-block;
  margin-top: .133333rem;
}

.follow_detail .card_footer {
  font-size: .266667rem;
  color: #333333;
  padding: 0 .266667rem;
  padding: .133333rem .266667rem;
  
}

.follow_detail .list {
  overflow: hidden;
}
.follow_detail .list li{
  position: relative;
}
.follow_detail .list li:after {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 1px;
  border-top: 1px solid #e9e9e9 !important;
  -webkit-transform: scaleY(.5);
  transform:scaleY(.5);
}

/* .follow_detail .added_Methods:before {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 1px;
  border-top: 1px solid #e9e9e9 !important;
  -webkit-transform: scaleY(.5);
  transform:scaleY(.5);
} */

.follow_detail .list li:first-child:after {
  content: "";
  border-top: none !important;
}

.follow_detail .van-cell:not(:last-child)::after {
  border-bottom: none !important;
}
</style>

<script>
import icon_mehotds1 from '@/assets/img/icon_addFollow1.png'
import icon_mehotds2 from '@/assets/img/icon_addFollow2.png'
import icon_mehotds3 from '@/assets/img/icon_addFollow3.png'
import icon_mehotds4 from '@/assets/img/icon_addFollow4.png'
import icon_mehotds5 from '@/assets/img/icon_addFollow5.png'

import {
  createNamespacedHelpers
} from "vuex";
let {
  mapState,
  mapGetters,
  mapMutations,
  mapActions
} = createNamespacedHelpers("followDetail");


export default {
  name: 'followDetail',
  data() {
    return {
      jwtAuth: {},
      followPopup: {
        title: '添加跟进',
        status: false,
      },
      minDate: new Date(),
      showAddPop: false,
      followStatusFirst: false,
      followStatusStop: false,
      methodsPopStatus: false,
      bottomSelectStatus: false,
      bottomAreaList: [],
      bottomSelectType: '',
      addMethodsValue: '',

      dialogType: '',

      updateFollow: {
        remark: '',
        followLevel: '',
        followLevelStatus: false,
        personId: '',
        personName: '请选择',
      },
      addForm: {
        nextFollowTime: '请选择',
        followLevel: '-1',
        remark: '',
        bmFollowCustomList: [
          {
            bmFollowCustomExitList: [
              {
                followCustomExitId: "1",
                followCustomExitRemark: "1",
                followCustomId: "1"
              }
            ],
            followCustomId: "1",
            followCustomName: "1",
            sort: 0,
            studentId: "83d0e5965e2f4c92964065772df91796"
          }
        ],
        bmFollowExitList: [
          {
            followCustomExitId: "1",
            followCustomExitRemark: "1",
            followCustomId: "1",
            followCustomName: "1",
            followExitId: "1",
            followId: "1"
          }
        ],
      },
      followList: [
        {},{},{}
      ],
      followData: {
        followType: {
          followTypeId: '',
          followTypeRemark: '',
          value: '请选择',
          id: '',
        },
        connection: {
          connectionId: '',
          connectionRemark: '',
          value: '请选择',
          id: '',
        },
        strength: {
          strengthId: '',
          strengthRemark: '',
          value: '请选择',
          id: '',
        },
        followResult: {
          followResultId: '',
          followResultRemark: '',
          value: '请选择',
          id: '',
        },
        nextFollow: {
          nextFollowId: '',
          nextFollowRemark: '',
          value: '请选择',
          id: '',
        },
      },

      salePersonList: [],
     
      followMethodsList: [
        {
          label: '跟进方式',
          icon: icon_mehotds1,
          type: 'followType',
        },
        {
          label: '连接情况',
          icon: icon_mehotds2,
          type: 'connection',
        },
        {
          label: '意向强度',
          icon: icon_mehotds3,
          type: 'strength',
        },
        {
          label: '跟进结果',
          icon: icon_mehotds4,
          type: 'followResult',
        },
      ],
      followMethodsListAdd: [
      ],
      followMethodsListAddData: [
      ],
      
      methodsPopTitle: '',
      methodsType: '',

      followMethodsRadioList: [
      ],

      newLabel: {},
      addLabelIndex: '',
      isAddLabel: false,
      isAddLabelId: '',
      showAddLabel: false,      // 超管显示添加标签 按钮
    }
  },

  watch: {
    addMethodsValue(newVal, oldVal) {

    }
  },

  created() {
    this.jwtAuth = JSON.parse(sessionStorage.getItem('jwtAuth'));
    this.initData();
    this.queryAllSchool();
    this.initFollowMethodsData();

    this.jwtAuth.bmRoleList.forEach(item => {
      if(item.dataPermissions == '40110') {
        this.showAddLabel = true;
      }
    })
    console.log(this.jwtAuth);
  },
  mounted() {
   
  },
  
  methods: {
    ...mapMutations([
      "updateInfo",
    ]),
    ...mapActions([
      "formGet",
      "post"
    ]),

    initData() {
      let data = {
        studentId: this.$route.params.id,
      };

      this.formGet({
        API: 'selectFollowForStudent',
        data: data
      }).then(res => {
        this.followList = res;
        this.updateFollow = this.followList[0];
        console.log(this.updateFollow)
      })
    },

    initFollowMethodsData() {
      this.post({
        API: 'selectBmFollowCustomPageList',
        data: {
          studentId: this.$route.params.id
        }
      }).then(res => {
        this.followMethodsListAddData = [];
        this.followMethodsListAdd = [];
        res.forEach((item, index) => {
          let obj = {
            label: item.followCustomName,
            icon: icon_mehotds5,
            id: item.followCustomId,
            // sort:
          }
          let obj2 = {
            followDataRemark: '',
            followDataId: '',
          }
          this.followMethodsListAddData.push(obj2)
          this.followMethodsListAdd.push(obj);
        })


      })
    },

    save() {
      let data = {};
      Object.assign(data, this.addForm);
      if(this.followData.followType.value == '请选择') {
        data.followTypeRemark = '';
      }else{
        data.followTypeRemark = this.followData.followType.value
        data.followTypeId = this.followData.followType.id
      }

      if(this.followData.followType.value == '请选择') {
        data.connectionRemark = ''
      }else{
        data.connectionRemark = this.followData.connection.value
        data.connectionId = this.followData.connection.id
      }

      if(this.followData.strength.value == '请选择') {
        data.strengthRemark = ''
      }else{
        data.strengthRemark = this.followData.strength.value
        data.strengthId = this.followData.strength.id
      }
      
      if(this.followData.followResult.value == '请选择') {
        data.followResultRemark = ''
      }else{
        data.followResultRemark = this.followData.followResult.value
        data.followResultId = this.followData.followResult.id
      }

      if(this.followData.nextFollow.value == '请选择') {
        data.nextFollowRemark = ''
      }else{
        data.nextFollowRemark = this.followData.nextFollow.value
        data.nextFollowId = this.followData.nextFollow.id
      }

      if(this.followData.newLabel) {
        data.bmFollowCustomList = [
          {
            bmFollowCustomExitList: [
              {
                followCustomExitId: this.followData.newLabel.id,
                followCustomExitRemark: this.followData.newLabel.value,
              }
            ],
            followCustomName: this.newLabel.label,
            sort: 0,
            studentId: this.$route.params.id
          }
        ]
      }

      data.studentId = this.$route.params.id

      if(data.nextFollowTime == '请选择') {
        data.nextFollowTime = ''
      }else{
        data.nextFollowTime = data.nextFollowTime + ':59'
      }

      data.createBy = this.jwtAuth.employeesId;
      
      
      console.log(data);
      // return false;

      this.post({
        API: 'insert',
        data: data
      }).then(res => {
        this.$notify({ type: 'success', message: '添加成功',duration: 1200 });
        this.initData();
        this.followPopup.status = false;
      })
    },
    update() {
      let followLevel = '';

      if(this.updateFollow.followLevelStatus) {
        followLevel = '10135';
      }else{
        followLevel = this.updateFollow.followLevel;
      }

      let data = {
        studentId: this.$route.params.id,
        followId: this.updateFollow.followId,
        followLevel: followLevel,
        personId: this.updateFollow.personId,
        personName: this.updateFollow.personName,
        remark: this.updateFollow.remark,
      }

      this.post({
        API: 'updateSetFollow',
        data: data
      }).then(res => {
        this.$notify({ type: 'success', message: '设置成功',duration: 1200 });
        this.initData();
        this.followPopup.status = false;
      })
    },

    clickRadio(type) {
      if(this.addForm.followLevel == type) {
        this.addForm.followLevel = '-1'
      }else{
        this.addForm.followLevel = type
      }
    },
    // 新增标签
    addFollowLabel() {
      this.showAddPop = true;
      this.dialogType = 'addLabel'
    },

    addFollow() {
      this.followPopup = {
        title: '添加跟进',
        status: true,
      }
    },

    showMethodsPop(item) {
      this.methodsPopStatus = true;
      this.methodsPopTitle = item.label;
      this.methodsType = item.type;
      this.dialogType = '';
      this.initFollowList();
      console.log(item);
      this.isAddLabel = false;
      this.isAddLabelId = '';
    },
    showMethodsPopAdd(item, index) {
      this.addLabelIndex = index
      this.methodsPopStatus = true;
      this.methodsPopTitle = item.label;
      this.methodsType = item.type;
      this.dialogType = '';
      this.initFollowAddList(item);
      console.log(item);
      if(item.id) {
        this.isAddLabel = true
        this.isAddLabelId = item.id;
      }
    },

    toFollowDetail(item) {
      // this.followPopup.title = '跟进详情'
      // this.followPopup.status = true;
      console.log(item);
    },


    showBottomSelect(type) {
      this.bottomSelectType = type
      this.bottomSelectStatus = true;
    },
    onConfirm(value, index) {
      console.log(`当前值：${value.id || value}, 当前索引：${index}`)

      if(this.bottomSelectType == 'date') {
        this.addForm.nextFollowTime = this.formatDate(value)
      }else{
        this.updateFollow.personName = this.bottomAreaList[index].employeesName;
        this.updateFollow.personId = value.id;
      }
      this.bottomSelectStatus = false;
    },
    onCancel() {
      this.bottomSelectStatus = false;
    },

    clickMethods(item) {
      console.log(item);
      if(item.followCustomExitId) {
        this.followMethodsListAddData[this.addLabelIndex].followDataRemark = item.followDataRemark;
        this.followMethodsListAddData[this.addLabelIndex].followDataId = item.followDataId;
        this.methodsPopStatus = false;
      }else{
        this.followData[item.followType].value = item.followDataRemark;
        this.followData[item.followType].id = item.followDataId;
        this.methodsPopStatus = false;
      }
      
    },

    onClose(clickPosition, instance, detail) {
      switch (clickPosition) {
        case 'left':
        case 'cell':
        case 'outside':
          instance.close();
          break;
        case 'right':
          this.$dialog.confirm({
            message: '确定删除吗？'
          }).then(() => {
            console.log(detail);
            console.log('aaaa')
            this.deleteTag(detail.name);
            instance.close();
          });
          break;
      }
    },

    onClose2(clickPosition, instance, detail) {
      switch (clickPosition) {
        case 'left':
        case 'cell':
        case 'outside':
          instance.close();
          break;
        case 'right':
          this.$dialog.confirm({
            message: '确定删除吗？'
          }).then(() => {
            console.log(detail);
            // console.log('aaaa')
            this.deleteMethods(detail.name);
            instance.close();
          });
          break;
      }
    },

    deleteMethods(id) {
      this.formGet({
        API: 'bmFollowCustomDeleteById',
        data: {
          id: id
        }
      }).then(res => {
        this.$notify({ type: 'success', message: '删除成功',duration: 1200 });
        this.initFollowMethodsData();
      })
    },

    deleteTag(id) {
      this.formGet({
        API: 'deleteById',
        data: {
          id: id
        }
      }).then(res => {
        this.$notify({ type: 'success', message: '删除成功',duration: 1200 });
        this.initFollowList();
      })
    },

    addMethodsItem(type) {
      this.addMethodsValue = '';
      this.showAddPop = true;
    },
    beforeCloseDialog(action, done) {
      if (action === 'confirm') {
        if(this.addMethodsValue == '') {
          done()
        }else{
          if(this.dialogType == 'addLabel') {
            let addObj = {
              label: this.addMethodsValue,
              icon: icon_mehotds5,
              type: 'newLabel',
            }

            let labelDataObj =  {
              followCustomExitId: '',
              followCustomExitRemark: '',
              value: '请选择',
              id: '',
            }
            // this.followData.newLabel = labelDataObj;
            // this.followMethodsListAdd.push(addObj);
            // this.followMethodsListAddData.push(labelDataObj);
            // this.newLabel = addObj;
            this.addLabel()
          }else{
            
            if(this.isAddLabel) {
              let obj = {
                followCustomExitRemark: this.addMethodsValue,
                followCustomId: this.isAddLabelId,
              }
              console.log('aaa');
              this.addFollowMethodsNew(obj);
              // this.followMethodsRadioList.push(obj)
            }else{
              let obj = {
                followDataRemark: this.addMethodsValue,
                followType: this.methodsType
              }
              this.addFollowMethods(obj)
            }
          }

          
        }
        this.addMethodsValue = ''
        done();
      } else {
        done();
      }
    },
    addLabel() {
      this.post({
        API: 'bmFollowCustomInsert',
        data: {
          followCustomName: this.addMethodsValue,
          sort: this.followMethodsListAdd.length + 1,
          studentId: this.$route.params.id,
        }
      }).then(res => {
        this.initFollowMethodsData();
      })
    },

    addFollowMethods(data) {
      this.post({
        API: 'insertFollowData',
        data: data
      }).then(res => {
        this.$notify({ type: 'success', message: '新增成功',duration: 1200 });
        this.initFollowList();
      })
    },
    addFollowMethodsNew(data) {
      this.post({
        API: 'bmFollowCustomExitInsert',
        data: data
      }).then(res => {
        this.$notify({ type: 'success', message: '新增成功',duration: 1200 });
        let obj = {
          id: this.isAddLabelId,
        }
        this.initFollowAddList(obj);
      })
    },
    initFollowList() {
      this.post({
        API: 'selectBmFollowDataPageList',
        data: {
          followType: this.methodsType
        }
      }).then(res => {
        console.log(res);
        this.followMethodsRadioList = res;
        console.log(this.followMethodsRadioList)
      })
    },
    initFollowAddList(item) {
      console.log(item);
      this.post({
        API: 'selectBmFollowCustomExitPageList',
        data: {
          followCustomId: item.id
        }
      }).then(res => {
        console.log(res);
        res.forEach(item => {
          item.followDataId = item.followCustomExitId;
          item.followDataRemark = item.followCustomExitRemark;
        })
        this.followMethodsRadioList = res;
      })
    },

    formatDate(date) {
      let month = (date.getMonth()+1) > 9 ? (date.getMonth()+1) : "0" + (date.getMonth()+1);
      let day = (date.getDate()) > 9 ? (date.getDate()) : "0" + (date.getDate());
      let hours = (date.getHours()) > 9 ? (date.getHours()) : "0" + (date.getHours());
      let minutes = (date.getMinutes()) > 9 ? (date.getMinutes()) : "0" + (date.getMinutes());
      let seconds = (date.getSeconds()) > 9 ? (date.getSeconds()) : "0" + (date.getSeconds());

      let dateString =
          date.getFullYear() + "-" +
          month + "-" +
          day + " " +
          hours + ":" +
          minutes
          
      return dateString; 
    },
    
    queryAllSchool(btnId) {
      let accountId
      this.jwtAuth.schoolId == '' ? accountId = '' : accountId = this.jwtAuth.accountId
      
      this.post({
        API: 'queryAllSchool',
        data: {
          accountId: accountId,
          menuId: btnId || 'studentManagement',
          schoolIds: this.jwtAuth.schoolId.split(','),
        }
      }).then(res => {
        res = res.filter(val => {
          return val.schoolId !== '';
        });

        this.schoolList = res;
        let schoolId = []
        this.schoolList.map((val) => {
          schoolId.push(val.schoolId);
        })

        let schoolIdStr = schoolId.join(',')

        this.queryAllPerson(schoolIdStr);

      }).catch(err => {
        // this.$toast.fail(err);
      })
    },
    queryAllPerson(schoolId) {
      this.formGet({
        API: 'queryPersonBySchoolId',
        data: {
          positionCode: '2,5',
          schoolId: schoolId,
        }
      }).then(res => {
        res.map((val) => {
          val.id = val.employeesId;
          val.label = val.employeesName;
        })
        // this.salePersonList = res;
        this.bottomAreaList = res;
        console.log(this.salePersonList);
      })
    },



    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      } else if (type === 'month') {
        return `${value}月`
      }else if (type === 'day') {
        return `${value}日`
      }else if (type === 'hour') {
        return `${value}点`
      }else if (type === 'minute') {
        return `${value}分`
      }
      return value;
    }

    
    
  },
  computed: {
    ...mapState([
    ]),

    computenIconFollowLevel() {
      return function(item) {
        if(item.followLevel == 1) {
          return 'icon_follow_level_first'
        }else if (item.followLevel == -1) {
          return ''
        }else{
          return 'icon_follow_level_stop'
        }
      }
    }
   
  },
  components: {
  },
}

</script>